package admin

import (
	"news_for_deepseek_interface/controller/admin"
	"news_for_deepseek_interface/controller/admin/classify"
	"news_for_deepseek_interface/controller/admin/drafts"
	"news_for_deepseek_interface/controller/admin/drafts_config"
	"news_for_deepseek_interface/controller/admin/drafts_log"
	news_create_config "news_for_deepseek_interface/controller/admin/news/create_config"
	"news_for_deepseek_interface/controller/admin/question_answer"
	"news_for_deepseek_interface/controller/admin/question_answer_import"
	"news_for_deepseek_interface/controller/admin/sync"
	"news_for_deepseek_interface/controller/admin/sync_config"
	"news_for_deepseek_interface/controller/admin/sync_log"
	"news_for_deepseek_interface/controller/admin/system/menu"
	"news_for_deepseek_interface/controller/admin/system/role"
	"news_for_deepseek_interface/controller/admin/system/user"
	"news_for_deepseek_interface/middleware"

	"github.com/gin-gonic/gin"
)

func StartRoutes(router *gin.Engine) {

	adminRouter := router.Group("/admin")
	{
		adminRouter.Use(middleware.AuthMiddleware())

		adminRouter.GET("routers", admin.Routers)

		adminRouter.GET("/balance", admin.Balance)

		//系统管理
		systemRouter := adminRouter.Group("/system")
		{
			//用户
			userGroup := systemRouter.Group("/user")
			{
				userGroup.POST("", user.List)
				userGroup.POST("/add", user.Create)
				userGroup.POST("/update", user.Update)
				userGroup.POST("/update_status", user.UpdateStatus)
				userGroup.POST("/delete", user.Delete)
				userGroup.GET("/is_super_admin", user.IsSuperAdmin)
			}

			//权限
			roleGroup := systemRouter.Group("/role")
			{
				roleGroup.GET("/all", role.All)
				roleGroup.POST("/my", role.My)
				roleGroup.POST("/update_user_role", role.UpdateUserRole)
				roleGroup.POST("/update_group", role.UpdateGroup)

				roleGroup.POST("", role.List)
				roleGroup.POST("/add", role.Create)
				roleGroup.POST("/update", role.Update)
				roleGroup.POST("/update_status", role.UpdateStatus)
				roleGroup.POST("/delete", role.Delete)
			}

			//分组
			menuGroup := systemRouter.Group("/menu")
			{
				menuGroup.GET("/all", menu.All)
				menuGroup.POST("/my", menu.My)

				menuGroup.POST("", menu.List)
				menuGroup.POST("/add", menu.Create)
				menuGroup.POST("/update", menu.Update)
				menuGroup.POST("/delete", menu.Delete)
			}
		}

		//分类管理
		classifyRouter := adminRouter.Group("/classify")
		{
			classifyRouter.GET("/all", classify.All)
			classifyRouter.GET("/list", classify.List)
			classifyRouter.POST("/create", classify.Create)
			classifyRouter.POST("/update", classify.Update)
			classifyRouter.POST("/delete", classify.Delete)
		}

		//问答管理
		questionAnswerRouter := adminRouter.Group("/question_answer")
		{
			questionAnswerRouter.GET("/list", question_answer.List)
			questionAnswerRouter.POST("/create", question_answer.Create)
			questionAnswerRouter.POST("/update", question_answer.Update)
			questionAnswerRouter.POST("/delete", question_answer.Delete)
			questionAnswerRouter.POST("/import", question_answer.Import)
		}

		//问答导入记录
		questionAnswerImportRecordRouter := adminRouter.Group("/question_answer_import")
		{
			questionAnswerImportRecordRouter.GET("/list", question_answer_import.List)
		}

		//草稿箱
		draftsRouter := adminRouter.Group("/drafts")
		{
			draftsRouter.GET("/list", drafts.List)
			draftsRouter.POST("/update", drafts.Update)
			draftsRouter.POST("/delete", drafts.Delete)
		}

		//草稿箱配置
		draftsConfigRouter := adminRouter.Group("/drafts_config")
		{
			draftsConfigRouter.GET("/detail", drafts_config.Detail)
			draftsConfigRouter.POST("/update", drafts_config.Update)
			draftsConfigRouter.POST("/count", drafts_config.Count)
		}

		//草稿箱日志
		draftsLogRouter := adminRouter.Group("/drafts_log")
		{
			draftsLogRouter.GET("/list", drafts_log.List)
		}

		//同步
		syncRouter := adminRouter.Group("/sync")
		{
			syncRouter.GET("/list", sync.List)
		}

		//发布配置
		syncConfigRouter := adminRouter.Group("/sync_config")
		{
			syncConfigRouter.GET("/detail", sync_config.Detail)
			syncConfigRouter.POST("/update", sync_config.Update)
			syncConfigRouter.POST("/count", sync_config.Count)
		}

		//发布日志
		syncLogRouter := adminRouter.Group("/sync_log")
		{
			syncLogRouter.GET("/list", sync_log.List)
		}

		//生成文章配置
		newsCreateConfigRouter := adminRouter.Group("/news_create_config")
		{
			newsCreateConfigRouter.GET("/list", news_create_config.List)
			newsCreateConfigRouter.POST("/create", news_create_config.Create)
			newsCreateConfigRouter.POST("/update", news_create_config.Update)
			newsCreateConfigRouter.POST("/delete", news_create_config.Delete)
			newsCreateConfigRouter.GET("/all", news_create_config.All)
		}
	}
}

func wrapHandlerWithParam(handler func(*gin.Context, string), param string) gin.HandlerFunc {
	return func(c *gin.Context) {
		handler(c, param)
	}
}
